package com.xbh.management.utils;

import com.xbh.management.model.ManDepartment;
import com.xbh.management.model.ManMenu;

import java.util.LinkedList;
import java.util.List;

/**
 * @program: management-center
 * @description: 递归遍历添加构成树形结构。
 * @author: 许宝华
 * @create: 2021-10-02 16:51
 */

public class TreeNodeUtil {

    /**
     * 菜单树
     * @param treeNodeList
     * @param parentIds
     * @return
     */
    public static List<ManMenu> transformData(List<ManMenu> treeNodeList, String parentIds){

        List<ManMenu> list=new LinkedList<ManMenu>();

        for (ManMenu node:treeNodeList){
            if (node.getParentId().toString().equals(parentIds)){
                node.setChildren(transformData(treeNodeList,node.getMenuId().toString()));
                list.add(node);
            }
        }
        return list;
    }

    /**
     * 部门树
     * @param treeNodeList
     * @param parentIds
     * @return
     */
    public static List<ManDepartment> transformDeptData(List<ManDepartment> treeNodeList, String parentIds){

        List<ManDepartment> list=new LinkedList<ManDepartment>();

        for (ManDepartment node:treeNodeList){
            if (node.getParentId().toString().equals(parentIds)){
                node.setChildren(transformDeptData(treeNodeList,node.getDepartmentId().toString()));
                list.add(node);
            }
        }
        return list;
    }
}
